package cn.yu.od;

import java.util.*;

/**
 * 银行插队
 * https://blog.csdn.net/banxia_frontend/article/details/129508567
 *
 * @Author : Ning Yu
 * @create 2023/3/25 11:45
 */
public class YinHuangChaDui {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        //事件数量
        int events = Integer.parseInt(scanner.nextLine());

        ArrayList<int[]> customers = new ArrayList<>();
        for (int i = 0; i < events; i++) {
            String[] ss = scanner.nextLine().split(" ");
            if(ss[0].equals("a") ){
                //排队
                int[] cus = new int[2];
                cus[0] = Integer.parseInt(ss[1]);
                cus[1] = Integer.parseInt(ss[2]);
                customers.add(cus);
            }else if(ss[0].equals("p")){
                //叫好
                int[] ints = customers.stream().sorted(Comparator.comparingInt(cus -> cus[0]))
                        .sorted(Comparator.comparingInt(cus -> cus[1]))
                        .findFirst().get();
                System.out.println(ints[0]);
                customers.remove(ints);
            }
        }

    }
}
